//
//  byNetworkHelper.m
//  bydo
//
//  Created by shaojinkuang on 1/29/16.
//  Copyright (c) 2016 JBY. All rights reserved.
//

#import "byNetworkHelper.h"

@implementation byNetworkHelper

+ (AFHTTPRequestOperationManager*)getNetManager {
    static AFHTTPRequestOperationManager* manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://duilian.msra.cn/app/"]];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
    });
    return manager;
}
+ (void)postJSONWithUrl:(NSString *)urlStr parameters:(id)parameters success:(void (^)(id))success fail:(void (^)())fail {
    [[byNetworkHelper getNetManager] POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            //NSString* iretString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
//            NSDictionary* iretDic = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
            success(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (fail) {
            NSLog(@"error is %@",error);
            fail();
        }
    }];
}
@end
